%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% COMPUTE THE TOTAL SUPPLY OF AVOIDED EMISSIONS AND PLOT THE CURVE

% "DEFORESTATION IN THE AMAZON:
% A UNIFIED FRAMEWORK FOR ESTIMATION AND POLICY ANALYSIS"

% by Eduardo Souza-Rodrigues

% This version: November 2018

% OBSERVATIONS: 
% Run this program after running "dem_def_reg.m" & "dem_def_carbon_emissions.m"

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% (A) COMPUTE TOTAL SUPPLY

% I. Load Data
% Total_emissions_for_farm_j = [co2_price' tot_co2_for_ivqr']
load Total_emissions_farm_1;
load Total_emissions_farm_2;
load Total_emissions_farm_3;
load Total_emissions_farm_4;

% II. Define Variables

% CO2 prices
co2_price = Total_emissions_farm_1(:,1);

% Total Avoided Emissions
emissions = Total_emissions_farm_1(:,2) + Total_emissions_farm_2(:,2) + Total_emissions_farm_3(:,2) + Total_emissions_farm_4(:,2);


%% (C) PLOT SUPPLY OF AVOIDED EMISSIONS OF CO2

% Avoided Emissions
avoid_emissions_fig = figure;
plot(emissions/(10^9),co2_price)
xlabel('Avoided Emissions of Carbon (Billion tons)','fontsize',15)
ylabel('US$ / tCO_2','fontsize',15)
title('Avoided Emissions of Carbon','fontsize',16)
axis([0 4.5 0 2])
saveas(avoid_emissions_fig,'AvoidEmissionCarbon.png')


%% (D) SHOW EMISSIONS AT $1/tCO2

disp('----------------------------------------------------------------------------')
disp([char('CARBON EMISSIONS AT $1/tCO2 (in billion tons of carbon):'), blanks(numel(emissions(11)/(10^9)))', num2str(emissions(11)/(10^9))])
disp('----------------------------------------------------------------------------')
pause


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
